package logic

import (
	"context"
	"fmt"
	"good_srv/good"
	"good_srv/internal/svc"
	"good_srv/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type ActiveShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewActiveShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ActiveShowLogic {
	return &ActiveShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ActiveShowLogic) ActiveShow(in *good.ActiveShowRequest) (*good.ActiveShowResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var a models.Active
	if err = a.Derail(); err != nil {
		logx.Error("活动详情展示失败")
		return nil, fmt.Errorf("活动详情展示失败")
	}

	return &good.ActiveShowResponse{
		Title:     a.Title,
		Price:     float32(a.Price),
		Num:       int64(a.Num),
		Image:     a.Image,
		Address:   a.Address,
		Tel:       a.Tel,
		Progress:  int64(a.Progress),
		Countdown: a.Countdown,
	}, nil
}
